The difference between CreateQuery and Createsqlquery in Hibernate is:The former uses the HQL statement to query, the latter can use the SQL statement queryThe formerHibernate-generated bean for object Mount list returnThe latter is stored as an array of objectsSo using createsqlquery sometimes also wants toHibernate-generated beans are not convenient for loading a list of objects.Suddenly discovered that Createsqlquery had a way to convert objects di
+ "% '";List catnamelist =gethibernatetemplate (). find (SQL);return catnamelist;OK, test to find no problem, it seems still because of the original SQL query reason, search online: Createsqlquery returned to the object, saw an article only to realize:Solution two (with native SQL query):String sql = "Select a.* from Tb_doc_catalog a where a.cat_code like '" +catcode+ "% '";Session session = This.getsession ();try {List catnamelist = session.createsqlquery (sql). Addentity (Doccataloginfo.class)
+ "% '";Session session = This.getsession ();try {List catnamelist = session.createsqlquery (sql). Addentity (Doccataloginfo.class). List ();return catnamelist;} finally {Releasesession (session); Release session}It's OK again.This article is also posted:The difference between CreateQuery and Createsqlquery in Hibernate is:The former uses the HQL statement to query, the latter can use the SQL statement queryThe former takes the bean generated by hiber
The original site of this article: Http://stta04.javaeye.com/blog/377633hibernate CreateQuery and CreatesqlqueryLast night to help colleagues see the code to 2 o'clock in the morning, this morning 6 o'clock woke up to find that he sent a message saying null pointer error, really can't sleep, up his own test, console also really reported:2009-4-25 8:12:34 Org.apache.catalina.core.ApplicationContext LogInfo: java.lang.ClassCastException: [Ljava.lang.Obj
Label:The difference between CreateQuery and Createsqlquery in Hibernate is:The former uses the HQL statement to query, the latter can use the SQL statement queryThe former takes the bean generated by hibernate as the object to load the list back, while the latter is stored as an array of objectsSo it's not very convenient to use createsqlquery and sometimes want to load the list back with hibernate-generated beans.Suddenly discovered that Createsqlqu
Tb_doc_catalog a where a.cat_code like '" +catcode+ "% '";Session session = This.getsession ();try {List catnamelist = session.createsqlquery (sql). Addentity (Doccataloginfo.class). List ();return catnamelist;} finally {Releasesession (session); Release session} It's OK again. This article is also posted: The difference between CreateQuery and Createsqlquery in Hibernate is:The former uses the HQL statement to query, the latter can use the SQL state
Tag: is the return entity storage method entities class Session object array creatThe former uses the HQL statement to query, the latter can be queried by the SQL statement, the former with Hibernate generated Bean (entity Class) for the object loading list returned, the latter is an object array to store;Createsqlquery has a method that can convert an object directly to query query = session.createsqlquery (SQL). addentity (Xxxxxxx.class); XXXXXXX represents the object of the bean generated by
like '" +catcode+ "% '";Session session = This.getsession ();try {List catnamelist = session.createsqlquery (sql). Addentity (Userinfo.class). List ();return catnamelist;} finally {Releasesession (session); Release session}It's OK again.The difference between CreateQuery and Createsqlquery in Hibernate is:The former uses the HQL statement to query, the latter can use the SQL statement queryThe former takes the bean generated by hibernate as the objec
Label:The difference between CreateQuery and Createsqlquery in Hibernate is:The former uses the HQL statement to query, the latter can use the SQL statement queryThe former takes the bean generated by hibernate as the object to load the list backThe latter is stored as an array of objects For example, after we get the session: CreateQuery: try{Session session=this.hibernatetemplate.getsessionfactory (). Get
Tags: exception on () Select Hibernate put exce lis query CTOThe difference between CreateQuery and Createsqlquery in Hibernate is:The former uses the HQL statement to query, the latter can use the SQL statement queryThe former takes the bean generated by hibernate as the object to load the list backThe latter is stored as an array of objects For example, after we get the session: CreateQuery: try{Session s
'" +catcode+ "% '";List catnamelist =gethibernatetemplate (). find (SQL);return catnamelist;OK, test to find no problem, it seems still because of the original SQL query reason, search online: Createsqlquery returned to the object, saw an article only to realize:Solution two (using native SQL query):String sql = "Select a.* from Tb_doc_catalog a where a.cat_code like '" +catcode+ "% '";Session session = This.getsession ();try {List catnamelist = session.createsqlquery (sql). Addentity (Doccatal
The difference between CreateQuery and Createsqlquery in Hibernate is:The former uses the HQL statement to query, the latter can use the SQL statement queryThe former takes the bean generated by hibernate as the object to load the list backThe latter is stored as an array of objectsSo it's not very convenient to use createsqlquery and sometimes want to load the list back with hibernate-generated beans.Createsqlquery has a way to convert objects direct
First, the basic content1. FROM clause A, simple usage: Public Ilist Getcustomerfrom () { // Returns an instance of all the customer classes return _session. CreateQuery ("fromcustomerentity"). List(); } B, aliases: Public Ilist Fromalias () { // Returns all instances of the Customer class, customer Assigned the alias customer return _session. CreateQuery ("fromcustomeren
1. query all fields of the entire ing object
Java code
// The direct from query shows a ing object, that is, querying all fields of the entire ing object.
String hql = "from users ";
Query query = session. createquery (hql );
List
Users = query. List ();
For (users user: Users ){
System. Out. println (user. getname () + ":" + User. getpasswd () + ":" + User. GETID ());
}
Output result:
Name1: password1: 1
Name2: password2: 2
JavaEE ------ Hibernate Study NotesHibernate framework needs to be configuredHibernate. cfg. xml file (which is set to connect to the database and MAP value object)
The value object is also required:
For example, Custom. hbm. xml is configured with values in hibernate (including the size of data fields in the database and IDs). The fields in xml must be the same value object in the value object and the modified xml file must be stored together.
Basically, some configuration files are
The three major frameworks of Java_Web: the foundation of Hibernate + HQL, java_webhql
12.1 HQL language basicsThe Hibernate Query Language is HQL (Hibernate Query Language). You can directly use the object class name and attributes. The HQL syntax is similar to SQL, and has SQL keywords such as select, from, order by, count (), and where. The difference is that HQL is a completely object-oriented language that can directly query object classes and attributes.12.1.1 HQL syntaxThe HQL syntax is s
been involved many times before, for example, the following example:
String hql = "from user ";
List list = session. createquery (hql). List ();
The code above is executed to query all the data corresponding to the user object, encapsulate the data into the user object, and put it in the list to return. It should be noted that there is a judgment on the inheritance relationship in the hibernate object query. For example, we have discussed the employe
From: http://www.router.net.cn/Article/26665.html If you do not know the persistent identifier of the object to be searched, you need to use hibernate to query. Here, I will share my experience with you and hope it will be useful to you. Hibernate supports powerful and easy-to-use object-oriented Query Language (hql ). If you want to create a query by programming, Hibernate provides a comprehensive query by criteria (QBC) and Hibernate query by example (QBE) function. You can also use native
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.